home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / cmouse.exe / CMOUSED.CPP < prev   
C/C++ Source or Header  |  1991-07-27  |  4KB  |  163 lines

  1. /*
  2.  
  3.     cmoused.cpp
  4.     7-27-91
  5.     demo of cmouse.cpp
  6.  
  7.     Copyright 1991
  8.     John W. Small
  9.     All rights reserved
  10.     Use freely but acknowledge authorship and copyright.
  11.  
  12.     PSW / Power SoftWare
  13.     P.O. Box 10072
  14.     McLean, Virginia 22102 8072 USA
  15.  
  16.     John Small
  17.     Voice: (703) 759-3838
  18.     CIS: 73757,2233
  19.  
  20. */
  21.  
  22. #include <conio.h>    /* clrscr(), gotoxy(), cprintf() */
  23. #include <stdlib.h>
  24. #include <graphics.h>
  25. #include <cmouse.hpp>
  26.  
  27. char *mice[] = {
  28.     "Unknown", "Bus", "Serial",
  29.     "InPort", "PS2", "HP"
  30. };
  31.  
  32. void MouseReport()
  33. {
  34.     (void) cprintf("\r\nMouse Driver Version : %d.%d%d",
  35.         MM.driverVersion >> 8,
  36.         (MM.driverVersion & 0x00F0) >> 4,
  37.         (MM.driverVersion & 0x000F));
  38.     (void) cprintf("\r\nRequires : %s Mouse",mice[MM.typeRequired]);
  39.     if (MM.present)
  40.         (void) cprintf("\r\nMouse has %2d buttons.",MM.buttons);
  41.     else
  42.         (void) cprintf("\r\nMouse not connected!");
  43.     (void) cprintf("\r\n\nMouse cursor @ (%3d,%3d)",MM.x,MM.y);
  44.     (void) cprintf("    Left  : %s",MM.leftPressed? "Down":"Up  ");
  45.     (void) cprintf("    Right : %s",MM.rightPressed? "Down":"Up  ");
  46.     (void) cprintf("\r\n%s button requested",
  47.         (MM.buttonRequested == MBleft)?
  48.         "Left " : "Right");
  49.     (void) cprintf("\r\nLeft:   Presses  : %3d  @ (%3d,%3d)   ",
  50.         MM.leftPresses, MM.lastLeftPressX,
  51.         MM.lastLeftPressY);
  52.     (void) cprintf("Releases : %3d  @ (%3d,%3d)",
  53.         MM.leftReleases, MM.lastLeftReleaseX,
  54.         MM.lastLeftReleaseY);
  55.     (void) cprintf("\r\nRight:  Presses  : %3d  @ (%3d,%3d)   ",
  56.         MM.rightPresses, MM.lastRightPressX,
  57.         MM.lastRightPressY);
  58.     (void) cprintf("Releases : %3d  @ (%3d,%3d)",
  59.         MM.rightReleases, MM.lastRightReleaseX,
  60.         MM.lastRightReleaseY);
  61.     (void) cprintf("\r\nMickeys :  Horz  : %10u   Vert  : %10u",
  62.         MM.horzMickeys, MM.vertMickeys);
  63.     (void) cprintf("\r\nEvent   :  Count : %10u   Time  : %10lu   Flags : %10u",
  64.         MM.eventCount, MM.eventTime, MM.eventFlags);
  65.     (void) cprintf("\r\nClicks  :  Left  : %10u   Right : %10u",
  66.         MM.leftClicks, MM.rightClicks);
  67.     (void) cprintf("\r\n@ time  :  Left  : %10lu   Right : %10lu",
  68.         MM.leftClickTime, MM.rightClickTime);
  69. }
  70.  
  71. main()
  72. {
  73.     unsigned ec;
  74.     int gdriver, gmode, gerror;
  75.     int dx, c;
  76.  
  77.     MM.open();
  78.     
  79.     clrscr();
  80.     gotoxy(10,20);
  81.     cprintf("Press any key to continue ...");
  82.     MM.show();
  83.     MM.autoEventUpdate();
  84.     ec = MM.eventCount;
  85.     MM.condOffZone(1,2,71,13);
  86.     while (!kbhit())  {
  87.         gotoxy(1,1);
  88.         MM.condOff();
  89.         MouseReport();
  90.         MM.show();
  91.         while ((ec == MM.eventCount) && !kbhit());
  92.         ec = MM.eventCount;
  93.     }
  94.     getch();  // clear keyboard buffer
  95.  
  96.     gdriver = DETECT;
  97.     initgraph(&gdriver, &gmode, "\\borlandc\\bgi");
  98.     gerror = graphresult();
  99.     if (gerror != grOk)  /* an error occurred */
  100.     {
  101.        clrscr();
  102.        cprintf("Not able to demo in graphics mode: %s",
  103.         grapherrormsg(gerror));
  104.        cprintf("\r\nPress any key to halt:");
  105.        getch();
  106.        exit(1);
  107.     }
  108.     MM.reset();  // call after any video mode change.
  109.     directvideo = 0;  // enable conio i/o in graphics mode
  110.  
  111.     dx = getmaxx() / (getmaxcolor()+1);
  112.     clearviewport();
  113.     for (c = 0; c <= getmaxcolor(); c++)  {
  114.         setfillstyle(XHATCH_FILL,c);
  115.  
  116.         bar3d(c*dx,0,(c+1)*dx,getmaxy(),0,0);
  117.     }
  118.  
  119.     gotoxy(10,20);
  120.     cprintf("Press any key to quit ...");
  121.  
  122.     MM.show();
  123.     MM.autoEventUpdate();
  124.     ec = MM.eventCount;
  125.     MM.condOffZone(0,0,570,208);
  126.     while (!kbhit())  {
  127.         gotoxy(1,1);  // conio remember!
  128.         MouseReport();
  129.         // CondOff() really belongs before MouseReport
  130.         // because conio is so slow I put it here.
  131.         // If you XOR_PUT to screen make sure mouse is
  132.         // hidden by condOff() or hide() before updating!
  133.         MM.condOff();
  134.         MM.show();
  135.         while ((ec == MM.eventCount) && !kbhit());
  136.         ec = MM.eventCount;
  137.     }
  138.     
  139.  
  140.     closegraph();
  141.     cputs("If you find cmouse useful and are using it in your");
  142.     cputs("\r\napplications, how about telling a friend about it.");
  143.     cputs("\r\nCmouse is freeware - I only ask that you leave my");
  144.     cputs("\r\ncopyright notice untouched!  I will try to answer");
  145.     cputs("\r\nas many of your questions and/or comments (time ");
  146.     cputs("\r\nand money permitting).  Thanks!  John CIS: 73757,2233");
  147.     cputs("\r\n");
  148.     cputs("\r\nPSW / Power SoftWare");
  149.     cputs("\r\nP.O. Box 10072");
  150.     cputs("\r\nMcLean, Virginia 22102 8072");
  151.     cputs("\r\n(703) 759-3838");
  152.     cputs("\r\n");
  153.     cputs("\r\nThat's all folks!");
  154.     cputs("\r\n");
  155.     cputs("\r\nPress enter to quit.");
  156.     getch();
  157.  
  158.     MM.close();
  159.     
  160.     return 0;
  161. }
  162.  
  163.